import {getSyllabusDetail} from "../../api/syllabus"
import {onMounted,reactive,ref} from "vue"
import {useStore} from "vuex"
export function useSyllabusDetail(){
	const BASE_URL = import.meta.env.VITE_BASE_API
	const {state} = useStore()
	const DAT = ref<any>([])
	const imgurl = ref("")
	function initSyllabusDetail(params:{
		CLASS_ID:string
		OPERATOR_ID:string
	}){
		return new Promise((resolve,reject)=>{
			getSyllabusDetail({
				CLASS_ID:params.CLASS_ID,
				OPERATOR_ID:state.user.userInfo.CUSER_ID
			})
			.then(res=>{
				if (res.ERROR[0].errcode == '0'){
					DAT.value = res.DAT
					imgurl.value = BASE_URL + "/pic_server/browse?picfilename=" + res.COUNT[0].WX_PIC
				    resolve(res)
				}else {
				    uni.showToast({
				        title: res.ERROR[0].error,
				        icon: 'none',
				        mask: true
				    })
				    reject('err')
				}
			})
			.catch(err=>{
				uni.showToast({
				    title: '获取列表失败',
				    icon: 'error',
				    mask: true
				})
				reject('err')
			})
		})
	}
	return {
		initSyllabusDetail,
		DAT,
		imgurl
	}
}